package net.towee.model.repo;

import net.towee.shared.exceptions.NameExistsException;


/**
 * Factory of documents
 * 
 * @author c58
 */
public interface DocumentFactory {

	/**
	 * This method create new empty document by given parameters and return it.
	 * 
	 * @param name
	 * @param groupId
	 * @param authorId
	 * @param parentNodeId
	 * 
	 * @return created document or null if given parameters not correct
	 */
	DocumentData createEmptyDocument(String name, String groupId, String authorId, String parentNodeId);
	
	/**
	 * This method validate given document, create tree node and generate ids.
	 * On success it return validated document with tree node field.
	 * Return null otherwise.
	 * 
	 * @param doc
	 * @param parentNodeId TODO
	 * @return
	 * @throws NameExistsException 
	 */
	DocumentData createDocument(DocumentData doc, String parentNodeId) throws NameExistsException;

	/**
	 * Create tree node by given parameters. Return created instance or null if
	 * node with given parenId or group not exists.
	 * 
	 * @param name
	 * @param parentNode
	 * @param groupId
	 * @return TreeNode instance on success, null on error
	 * @throws NameExistsException 
	 */
	TreeNode createTreeNode(String name, String parentNode, String groupId) throws NameExistsException;

	/**
	 * This method create DocumentPatch and DocumentDiff. The last one it add to given
	 * newDoc. Return pair of DocumentPatch and DocumentData ready to save.
	 * 
	 * @param docId
	 * @param newDoc
	 * @return
	 * @throws NameExistsException 
	 */
	DocumentData createChangeset(String docId, DocumentData newDoc, String authorId,
			String explain) throws NameExistsException;
}
